/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package api;


import cz.muni.restinterface.CustomerDTO;
import org.codehaus.jackson.JsonNode;
import org.springframework.http.HttpEntity;

/**
 *
 * @author osiris
 */
public class RestClientCustomerImpl extends RestClientAPI implements RestClientCustomerInterface {
    
    
    public RestClientCustomerImpl(String url) {

       super(url);
    }
    
    
    @Override
    public void create(CustomerDTO customer) {
        
        HttpEntity<CustomerDTO> entity = new HttpEntity<CustomerDTO>(customer,headers);
        uri =  rt.postForLocation(
        url.concat("create="),entity);       
    }
    
    @Override
    public void findall() {
    
        JsonNode jsonNode = rt.getForObject(url.concat("/findall"), JsonNode.class);
         for(JsonNode m : jsonNode) {
            System.out.println("entry = " + m);
        }
    }
    
    @Override
    public JsonNode findByFirstName(String firstName) {
        
        return rt.getForObject(url.concat("/findByFirstName/").concat(firstName), JsonNode.class);
    
    }

    @Override
    public void delete(String id) {
        System.out.println("Dostali sme sa do metody delete na strane klienta s IDckom:"+id);
        rt.delete(url.concat("delete=").concat(id)); 
    }

    @Override
    public void update(CustomerDTO customer) {
        HttpEntity<CustomerDTO> entity = new HttpEntity<CustomerDTO>(customer,headers);
        rt.put(url.concat("update="),entity);      
    }

    @Override
    public JsonNode findByLastName(String LastName) {
         return rt.getForObject(url.concat("/findByLastName/").concat(LastName), JsonNode.class);
    }

    @Override
    public JsonNode findByEmail(String email) {
        return rt.getForObject(url.concat("/findByEmail/").concat(email), JsonNode.class);
    }

    @Override
    public JsonNode findByPhoneNumber(String phoneNumber) {
        return rt.getForObject(url.concat("/findByPhoneNumber/").concat(phoneNumber), JsonNode.class);
    }

    @Override
    public JsonNode findById(String id) {
          return rt.getForObject(url.concat("findbyid=").concat(id), JsonNode.class);
    }

   
    
   
    
}
